﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Administracija.master" AutoEventWireup="true" CodeFile="AdministracijaClanaka.aspx.cs" Inherits="AdministracijaClanaka" ValidateRequest="false"%>
<%@ Register Assembly="CKEditor.NET" Namespace="CKEditor.NET" TagPrefix="CKEditor" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" Runat="Server">
    <script src="Skripte/Administracija/AdministracijaClanaka.js" type="text/javascript"></script>
    <script src="ckeditor/ckeditor.js" type="text/javascript"></script>
    <link href="Stilovi/AdministracijaClanak.css" rel="stylesheet" type="text/css" />
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="ContentPlaceHolder1" Runat="Server">
        <div id="administracijaMeni">
                 <ul class="meni_lista">
                    <li><a href="Administracija.aspx">Administracija naslovna</a></li>
                    <li><a href="AdministracijaSlika.aspx">Administracija slika</a></li>
                    <li><a href="AdministracijaDrveca.aspx">Administracija drveća</a></li>
                    <li><a href="AdministracijaRasadnika.aspx">Administracija rasadnika</a></li>
                 </ul>
     </div>
     <div id="glavni">
     <!---------------------------Poglavlja clanaka----------------------------------------------------------------->
         
         <asp:SqlDataSource ID="sdsPoglavlja" runat="server" 
             ConnectionString="<%$ ConnectionStrings:EnciklopedijaDrvecaConnectionString %>" 
             SelectCommand="SELECT * FROM [poglavlje]"></asp:SqlDataSource>

             <h2 class="naslov_poglavlja">Popis poglavlja</h2>
             <div class="grid_container">
         <asp:GridView ID="grdPoglavlja" runat="server" AllowPaging="True" 
             AllowSorting="True" AutoGenerateColumns="False" DataKeyNames="PoglavljeID" 
             DataSourceID="sdsPoglavlja" BackColor="#000066" CellPadding="10" ForeColor="White">
             <AlternatingRowStyle BackColor="#000099" ForeColor="White" />
             <Columns>
                 <asp:CommandField ShowSelectButton="True" CausesValidation="False" 
                     SelectText="Odaberi" >
                 <ItemStyle Font-Bold="True" />
                 </asp:CommandField>
                 <asp:BoundField DataField="PoglavljeID" HeaderText="Id poglavlja" 
                     InsertVisible="False" ReadOnly="True" SortExpression="PoglavljeID" />
                 <asp:BoundField DataField="NazivPoglavlja" HeaderText="Naziv poglavlja" 
                     SortExpression="NazivPoglavlja" />
                 <asp:BoundField DataField="GalerijaID" HeaderText="Id galerije" 
                     SortExpression="GalerijaID" />
             </Columns>
             <HeaderStyle BackColor="Black" />
             <SelectedRowStyle BackColor="#006600" />
         </asp:GridView>
         </div>
      <!---------------------------Poglavlja clanaka----------------------------------------------------------------->

      <!---------------------------ClanakEditDialog-------------------------------------------------->
      <div id="editiranjeClankaDialog" class="editiranjeClanakaDialog">
    <CKEditor:CKEditorControl id="editText" runat="server" ClientIDMode="Static"></CKEditor:CKEditorControl>
    <asp:Button id="btnEditiranjeOk" class="btnEditiranjeOk" runat="server" Text="Potvrdi" />
    <asp:Button id="btnEditiranjeOdustani" class="btnEditiranjeOdustani" runat="server" Text="Odustani" />
    
    </div>

      <!---------------------------ClanakEditDialog-------------------------------------------------->

     <!----------------------------Pregled i editiranje clanaka------------------------------------>
        <div id="pregledIeditiranjeClanaka">
        <h2>Pregled i editiranje članaka</h2>
         <asp:SqlDataSource id="sdsClanci" runat="server" 
                ConnectionString="<%$ ConnectionStrings:EnciklopedijaDrvecaConnectionString %>" 
                DeleteCommand="DELETE FROM [Clanak] WHERE [ClanakID] = @ClanakID" 
                InsertCommand="INSERT INTO [Clanak] ([NazivClanka], [TextClanka], [DatumPisanja], [PoglavljeID], [GalerijaID]) VALUES (@NazivClanka, @TextClanka, @DatumPisanja, @PoglavljeID, @GalerijaID)" 
                SelectCommand="SELECT clanak.*,galerija.*,poglavlje.*  FROM [Clanak] inner join galerija on
                clanak.galerijaid=galerija.galerijaid inner join poglavlje on clanak.poglavljeid=poglavlje.poglavljeid where poglavlje.poglavljeid=@poglavljeid" 
                UpdateCommand="UPDATE [Clanak] SET [NazivClanka] = @NazivClanka, [DatumPisanja] = @DatumPisanja, [PoglavljeID] = @PoglavljeID, [GalerijaID] = @GalerijaID WHERE [ClanakID] = @ClanakID">
             <DeleteParameters>
                 <asp:Parameter Name="ClanakID" Type="Int32" />
             </DeleteParameters>
             <SelectParameters>
                <asp:ControlParameter ControlID="grdPoglavlja" Name="PoglavljeId" 
                    PropertyName="SelectedValue" />
            </SelectParameters>
             <InsertParameters>
                 <asp:Parameter Name="NazivClanka" Type="String" />
                 <asp:Parameter Name="TextClanka" Type="String" />
                 <asp:Parameter Name="DatumPisanja" Type="DateTime" />
                 <asp:Parameter Name="PoglavljeID" Type="Int32" />
                 <asp:Parameter Name="GalerijaID" Type="Int32" />
             </InsertParameters>
             <UpdateParameters>
                 <asp:Parameter Name="NazivClanka" Type="String" />
                 <asp:Parameter Name="TextClanka" Type="String" />
                 <asp:Parameter Name="DatumPisanja" Type="DateTime" />
                 <asp:Parameter Name="PoglavljeID" Type="Int32" />
                 <asp:Parameter Name="GalerijaID" Type="Int32" />
                 <asp:Parameter Name="ClanakID" Type="Int32" />
             </UpdateParameters>
            </asp:SqlDataSource>
            <div class="grid_container">
         <asp:GridView id="grdClanci" runat="server" AllowPaging="True" AllowSorting="True" 
                AutoGenerateColumns="False" DataKeyNames="ClanakID" DataSourceID="sdsClanci" 
                    BackColor="#000066" CellPadding="10" ForeColor="White">
             <AlternatingRowStyle BackColor="#000099" />
             <Columns>
                 <asp:CommandField ShowDeleteButton="True" ShowEditButton="True" 
                     CancelText="Odustani" DeleteText="Izbriši" EditText="Uredi" InsertText="Ubaci" 
                     NewText="Novo" SelectText="Odaberi" UpdateText="Potvrdi" >
                     <ItemStyle Font-Bold="True" />
                 </asp:CommandField>
                 <asp:BoundField DataField="ClanakID" HeaderText="Id članka" 
                     InsertVisible="False" ReadOnly="True" SortExpression="ClanakID" />
                 <asp:BoundField DataField="NazivClanka" HeaderText="Naziv članka" 
                     SortExpression="NazivClanka" />
                 <asp:BoundField DataField="TextClanka" HeaderText="Text članka" 
                     SortExpression="TextClanka" Visible="False" />
                 <asp:BoundField DataField="DatumPisanja" HeaderText="Datum pisanja" 
                     SortExpression="DatumPisanja" />
                 <asp:BoundField DataField="PoglavljeID" HeaderText="Id poglavlja" 
                     SortExpression="PoglavljeID" Visible="True" />
                 <asp:BoundField DataField="GalerijaID" HeaderText="Id galerije" 
                     SortExpression="GalerijaID" Visible="True" />
                 <asp:TemplateField HeaderText="Naziv galerije">
                     <ItemTemplate>
                         <asp:Label ID="lblNazivGalerije" runat="server" Text='<%# Eval("NazivGalerije") %>'></asp:Label>
                     </ItemTemplate>
                     
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Naziv poglavlja">
                        <ItemTemplate>
                         <asp:Label ID="lblNazivPoglavlja" runat="server" Text='<%# Eval("NazivPoglavlja") %>'></asp:Label>
                     </ItemTemplate>
                 </asp:TemplateField>
                 <asp:TemplateField HeaderText="Uredi članak">
                     <ItemTemplate>
                         <asp:Button ID="Button1" runat="server" Text="Uredi sadržaj" CssClass="btnEditClanak" />
                     </ItemTemplate>
                 </asp:TemplateField>
             </Columns>
             <HeaderStyle BackColor="Black" />
             <SelectedRowStyle BackColor="#006600" />
            </asp:GridView>
            </div>
        </div>
          <!----------------------------Pregled i editiranje clanaka------------------------------------>
          <!------------------------------------Dodavanje clanaka------------------------------------------------->
          <h2>Dodavanje novog članka</h2>
          <div id="dodavanjeClanka">
          <div class="grid_container">
               
        <div id="porukaOdodavanjuClanka" runat="server"></div>
        <p>
            <asp:Label id="lblNazivClanka" runat="server" Text="Naziv članka: "></asp:Label>
            <asp:TextBox id="txtNazivClanka" runat="server" ValidationGroup="grupaDodajClanak"></asp:TextBox>
            <br />
            <asp:RequiredFieldValidator ControlToValidate="txtNazivClanka" ForeColor="Red" ID="RequiredFieldValidator3" runat="server" ErrorMessage="Morate upisati naziv članka" ValidationGroup="grupaDodajClanak"></asp:RequiredFieldValidator>
        </p>


        <h2>Unesite text članka </h2>
        <p>
        <CKEditor:CKEditorControl runat="server" id="ftbClanakODrvetu"></CKEditor:CKEditorControl>
        </p>


        <p>
            <asp:Label id="lbDodavanjeClanakalNazivGalerije" runat="server" Text="Naziv galerije: "></asp:Label>
            <asp:DropDownList id="ddlNazivGalerije" runat="server" 
                DataSourceID="sdsClanciGalerija" DataTextField="NazivGalerije" 
                DataValueField="GalerijaID"></asp:DropDownList>
            <asp:SqlDataSource id="sdsClanciGalerija" runat="server"
                    ConnectionString="<%$ ConnectionStrings:EnciklopedijaDrvecaConnectionString %>" 
                     SelectCommand="SELECT * FROM [Galerija]" >
                </asp:SqlDataSource>
        </p>

     
        <p>
            <asp:Label id="lblDodavanjeClanakaNazivPoglavlja" runat="server" Text="Naziv poglavlja: "></asp:Label>
            <asp:DropDownList id="ddlDodavanjeClanakaNazivPoglavlja" runat="server" 
                DataSourceID="sdsClanciPoglavlje" DataTextField="NazivPoglavlja" 
                DataValueField="PoglavljeID"></asp:DropDownList>
                <asp:SqlDataSource id="sdsClanciPoglavlje" runat="server"
                    ConnectionString="<%$ ConnectionStrings:EnciklopedijaDrvecaConnectionString %>" 
                     SelectCommand="SELECT * FROM [Poglavlje]" >
                </asp:SqlDataSource>
        </p>

       
        <p>
            <span>
            <asp:Button id="btnDodajClanak" runat="server" Text="Dodaj članak" 
                ValidationGroup="grupaDodajClanak" onclick="btnDodajClanak_Click"  />
            </span>
            
        </p>
        
        </div>
          </div>
            <!------------------------------------Dodavanje clanaka------------------------------------------------->

     </div>
</asp:Content>

